package com.isunland.managesystem.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseButterKnifeAdapter;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.entity.DataStatus;
import com.isunland.managesystem.entity.rOutappMain;
import com.isunland.managesystem.utils.MyStringUtil;
import com.isunland.managesystem.widget.CustomTextView;
import java.util.ArrayList;

/**
 * 对象功能:  出库adapter
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/6/28 14:50
 */
public class RetailOutAdapter extends BaseButterKnifeAdapter<rOutappMain> {

  public static final int ORDER_SALE = 0; //销售订单
  public static final int RETAIL_OUT = 1; //其他出库

  private int mType;
  private Context context;

  public RetailOutAdapter(BaseVolleyActivity context, ArrayList<rOutappMain> objects, int type) {
    super(context, objects);
    this.context = context;
    this.mType = type;
  }

  @Override protected int setLayoutId() {
    return R.layout.adapter_out_list;
  }

  @NonNull @Override protected BaseViewHolder initHolder(View convertView) {
    return new ViewHolder(convertView);
  }

  @Override protected void initView(rOutappMain item, BaseViewHolder baseHolder, int position) {
    ViewHolder holder = (ViewHolder) baseHolder;
    if (ORDER_SALE == mType) {
      //销售订单
      holder.tvTitle1.setText(item.getMcustomerName());//客户
      holder.tvTitle1.setVisibility(
          TextUtils.isEmpty(item.getMcustomerName()) ? View.GONE : View.VISIBLE);
      holder.tvTitle2.setText(
          MyStringUtil.connect(item.getMaterialKindName(), context.getString(R.string.colon),
              item.getMoutCom()));//物料类别: 物品
    }
    if (RETAIL_OUT == mType) {
      //其他出库
      holder.tvTitle1.setText(item.getMoutCom());//概要
      holder.tvTitle1.setVisibility(
          TextUtils.isEmpty(item.getMoutCom()) ? View.GONE : View.VISIBLE);
      holder.tvTitle2.setText(item.getMaterialKindName());//物料类别
    }

    holder.tvContent1.setText(item.getMoutbillNo());//单据编号
    holder.tvContent2.setText(item.getRegDate());//登记时间
    holder.tvStatus.setText(
        DataStatus.getDataStatusName(item.getMoutbillStatus(), DataStatus.KIND_ORDER));//数据状态
    holder.tvStatus.setTextColor(
        DataStatus.getDataStatusColor(context, item.getMoutbillStatus(), DataStatus.KIND_ORDER));
    holder.ivLogo.setText(MyStringUtil.substring(item.getStorageName(), 0, 2));
  }

  protected class ViewHolder extends BaseViewHolder {
    @BindView(R.id.iv_logo) CustomTextView ivLogo;
    @BindView(R.id.tv_title1) TextView tvTitle1;
    @BindView(R.id.tv_status) TextView tvStatus;
    @BindView(R.id.tv_title2) TextView tvTitle2;
    @BindView(R.id.tv_content1) TextView tvContent1;
    @BindView(R.id.tv_content2) TextView tvContent2;

    ViewHolder(View view) {
      super(view);
      ButterKnife.bind(this, view);
    }
  }
}
